package com.xk.Colletcion.Set;

import com.xk.Colletcion.pojo.Student;

import java.util.HashSet;
import java.util.Set;

public class setTest {
    public static void main(String[] args) {
        Set<Student> studentSet = new HashSet<>();
        Student student1 = new Student("小王", 19, "男", 101, 3);
        Student student2 = new Student("小刘", 20, "男", 102, 3);
        Student student3 = new Student("小张", 21, "女", 103, 3);
        studentSet.add(student1);
        studentSet.add(student2);
        studentSet.add(student3);

        //
        System.out.println("原始数据：");
        for (Student s : studentSet) {
            System.out.println(s.toString());
        }
        //删除数据
        studentSet.remove(student1);
        System.out.println("采用remove方法删除第一条数据数据：");
        for (Student s : studentSet) {
            System.out.println(s.toString());
        }

        // 判断该Set集合是否包含特定的元素
        System.out.println("判断该Set集合是否包含特定的元素:");
        boolean isContained = studentSet.contains(student2);
        if (isContained) {
            System.out.println("该集合中有"+student2.getName()+"的信息");
        } else {
            System.out.println("该集合中没有"+student2.getName()+"的信息");

        }
        System.out.println(student2);

        //判断该集合是否为空
        System.out.println("判断该集合是否为空:");
        boolean result=studentSet.isEmpty();
        if (result){
            System.out.println("该集合为空！");
        }else
            System.out.println("该集合不为空,数据为：");
        for (Student s:studentSet){
            System.out.println(s.toString());
        }

        //判断该集合中有多少条信息

        System.out.println("判断该集合中有多少条信息:");
        int count=studentSet.size();
        System.out.println(count+"条信息");

        //删除所有的数据
        System.out.println("采用clear删除所有的数据:");
        studentSet.clear();
    }

}
